#include"bits/stdc++.h"
using namespace std;
const int MAXN=100000+10;
struct mengxiong{
	string name;
	double average,fluctuation_value;
	int grade[21];
};
int n,m,sum[MAXN],fl[MAXN];
mengxiong student[MAXN];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>student[i].name;
		for(int j=1;j<=m;j++)
		{
			cin>>student[i].grade[j];
			sum[i]+=student[i].grade[j];
		}
		student[i].average=(sum[i]*1.0)/(n*1.0);
		for(int j=1;j<=m;j++)
		{
			fl[i]+=pow((student[i].grade[j]-student[i].average),2);
		}
		fl[i]/=m;
		student[i].fluctuation_value=sqrt(fl[i]);
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			if(student[j].fluctuation_value<student[j+1].fluctuation_value)
			{
				swap(student[j],student[j+1]);
			}
			else if(student[j].fluctuation_value==student[j+1].fluctuation_value)
			{
				if(student[j].name>student[j+1].name)
				{
					swap(student[j],student[j+1]);
				}
			}
		}
	}
	if(n<=20)
	{
		for(int i=1;i<=n;i++)
		{
			cout<<student[i].name<<" "<<sum[i]<<" "<<student[i].average<<" "<<student[i].fluctuation_value<<endl;
		}
	}
	else
	{
		for(int i=1;i<=20;i++)
		{
			cout<<student[i].name<<endl;
		}
	}
}
